export const formatMenu = (menuList, value) => {
  function findPath(menus, targetValue, path = []) {
    for (let menu of menus) {
      path.push(menu.label)
      if (menu.value === targetValue) {
        return path.slice()
      }
      if (menu.children && menu.children.length > 0) {  
        const childPath = findPath(menu.children, targetValue, path) 
        if (childPath.length > 0) {
          return childPath // 如果在子菜单中找到了路径，则返回它  
        }
      }
      path.pop() // 回溯，尝试下一条路径
    }
    return []
  }  
  
  const path = findPath(menuList, value)
  path.pop()
  return path.join('/')
}

export const findObjectByValue = (orgList, id) => {
  // 首先检查顶级对象
  const topLevelObject = orgList.find(obj => obj.orgCode === id)
  if (topLevelObject) {
    return { orgCode: topLevelObject.orgCode, orgName: topLevelObject.orgName }
  }  
  // 如果没找到，再检查children  
  for (const obj of orgList) {
    if (obj.children && Array.isArray(obj.children)) {
      const childObject = obj.children.find(child => child.orgCode === id)
      if (childObject) {
        return { orgCode: childObject.orgCode, orgName: childObject.orgName }
      }
    }
  }
  return null
}